<template>
  <div class="sideBar">
    <div class="projectTitle" :class="$store.state.isCollapse?'menu-bar-collapse-width':'menu-bar-width'" :style="'background-color:'+themeColor">
      <img v-if="$store.state.isCollapse" class="logo" src="@/assets/logo.png">
      <div v-else class="appName">{{appName}}</div>
    </div>
    <el-menu class="el-menu-vertical-demo" :collapse="$store.state.isCollapse" :unique-opened="true" :router="true" :default-active="$route.path || ''">
      <el-submenu v-for="(item,index) in menuList" :key="index" :index="String(index+1)">
        <template slot="title">
          <i :class="item.icon"></i>
          <span slot="title">{{item.title}}</span>
        </template>
        <el-menu-item :index="menu.url" v-for="(menu,menuIndex) in item.menus" :key="menuIndex">{{menu.name}}</el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
  import Menu from '@/lib/menu'

  const { menuList } = Menu;
  export default {
    name: 'sideBar',
    components: {
    },
    data(){
      return {
        themeColor: this.$store.state.themeColor,  //主题颜色
        appName: this.$store.state.appName,
        menuList: menuList,
      }
    },
    methods: {
      changeCollapse(){  //改变导航栏状态
        this.$store.commit('changeCollapse');
      }
    },
    created() {
    }
  }
</script>

<style lang="scss" scoped>
.sideBar{
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1020;
  .projectTitle{
    transition:0.3s;
    height: 64px;
    text-align: center;
    line-height: 64px;
    border-right: solid 1px #e6e6e6;
    .appName{
      color: white;
      font-size: 25px;
    }
    .logo{
      margin: 12px;
      width: 40px;
      height: 40px;
    }
  }
  .menu-bar-width {
    width: 200px;
  }
  .menu-bar-collapse-width {
    width: 64px;
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
    .el-submenu{
      i{
        margin-right: 10px;
      }
    }
  }
}
</style>